#!/bin/ruby

# script to disassemble a short patch of code
# beginning at a specified address
# we give the address as an absolute address.

if ARGV.size < 1
    puts "Insert coin"
    exit
end

off = ARGV[0].hex

elf = "hello.elf"
dis = "xtensa-lx106-elf-objdump -mxtensa -d #{elf} -z "

base = 0x40100000

count = 128
ss = "%08x" % (off)
es = "%08x" % (off + count)

range = "--start-address=0x#{ss} --stop-address=0x#{es}"

# We could use a pipeline, but ....
cmd = dis + range + "> short.tmp"
#puts cmd
system cmd
system "./fix_endian short.tmp"
File.delete "short.tmp"

# THE END
